package eleanor.ltd.isRealEstate.dao.client;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Query;
import org.hibernate.Session;

import eleanor.ltd.isRealEstate.entities.client.Client;


public class ClientDAOImpl implements ClientDAO {

	@Inject
	private Session session;

	public boolean save(Client client) {
		if (client != null) {
			session.save(client);
			return true;
		}
		return false;
	}

	public Client findById(String id) {
		return (Client) session.get(Client.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<Client> findAll() {
		return session.createCriteria(Client.class).list();
	}

	public List<Client> findByUserID(Long id) {
		// TODO Auto-generated method stub
		Query q = session.createQuery("Select id from client where userID = " + id);
		return q.list();
	}
	
}
